//
//  HMBaseNavController.swift
//  SinaWeibo
//
//  Created by apple on 16/9/22.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class HMBaseNavController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

   //重写push方法
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        //一旦空实现这个方法 导航视图控制器无法设置根视图控制器
        //UINavigationController(rootViewController:) 内部执行了push
        print(childViewControllers.count)
        let count = childViewControllers.count
        if count > 0 {
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "返回", imageName: "navigationbar_back_withtext", target: self, action: #selector(back))
            //当进入子页面的时候 隐藏底部的tabbar
            viewController.hidesBottomBarWhenPushed = true
        }
        super.pushViewController(viewController, animated: animated)
        print(childViewControllers.count)
    }
    
    
    //返回
    @objc private func back() {
        //pop
        self.popViewController(animated: true)
    }

}
